package santeclair.referentiel.optique.model;

import static javax.persistence.GenerationType.IDENTITY;

import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import santeclair.lunar.framework.annotation.Code;
import santeclair.lunar.framework.annotation.HashCodeEquals;
import santeclair.lunar.framework.annotation.ToString;
import santeclair.lunar.framework.util.EqualsUtils;
import santeclair.lunar.framework.util.HashCodeUtils;
import santeclair.lunar.framework.util.ToStringUtils;
import santeclair.referentiel.optique.config.Constant;

@Entity
@Table(name = "tr_type_vision", catalog = Constant.SCHEMA_NAME, uniqueConstraints = @UniqueConstraint(columnNames = "code_type_vision"))
public class TypeVision implements java.io.Serializable {

    private static final long serialVersionUID = -8419958227323442528L;

    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "identifiant_type_vision", unique = true, nullable = false)
    @ToString
    @HashCodeEquals
    private Integer identifiantTypeVision;

    @Code
    @Column(name = "code_type_vision", unique = true, nullable = false, length = 10)
    @ToString
    @HashCodeEquals
    private String codeTypeVision;

    @Column(name = "libelle_type_vision", nullable = false)
    @ToString
    @HashCodeEquals
    private String libelleTypeVision;

    @ManyToMany(fetch = FetchType.LAZY, targetEntity = GeometrieVerre.class, mappedBy = "typeVisions")
    /*Ne ajouter les annotations @ToString et @HashCodeEquals*/
    private Set<GeometrieVerre> geometrieVerres;

    public TypeVision() {
    }

    public Integer getIdentifiant() {
        return this.identifiantTypeVision;
    }

    public void setIdentifiant(Integer identifiantTypeVision) {
        this.identifiantTypeVision = identifiantTypeVision;
    }

    public String getCode() {
        return this.codeTypeVision;
    }

    public void setCode(String codeTypeVision) {
        this.codeTypeVision = codeTypeVision;
    }

    public String getLibelle() {
        return this.libelleTypeVision;
    }

    public void setLibelle(String libelleTypeVision) {
        this.libelleTypeVision = libelleTypeVision;
    }

    public Set<GeometrieVerre> getGeometrieVerres() {
        return this.geometrieVerres;
    }

    public void setGeometrieVerres(Set<GeometrieVerre> geometrieVerres) {
        this.geometrieVerres = geometrieVerres;
    }

    @Override
    public String toString() {
        return ToStringUtils.toString(this);
    }

    @Override
    public int hashCode() {
        return HashCodeUtils.hashCode(this);
    }

    @Override
    public boolean equals(Object obj) {
        return EqualsUtils.isEqual(this, obj);
    }

}
